package com.groupbuying.redpacket.config;

import com.groupbuying.redpacket.intercepter.AuthIntercepter;
import com.groupbuying.redpacket.intercepter.RedPacketIntercepter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AuthConfig implements WebMvcConfigurer {
    @Bean
    public AuthIntercepter authIntercepter() {
        return new AuthIntercepter();
    }
    @Bean
    public RedPacketIntercepter redPacketIntercepter(){
        return new RedPacketIntercepter();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration addInterceptor = registry.addInterceptor(authIntercepter());
        // 排除配置
        addInterceptor.excludePathPatterns("/error/");
        addInterceptor.excludePathPatterns("/login/**");
        addInterceptor.excludePathPatterns("/test/**");
        // 拦截配置
        addInterceptor.addPathPatterns("/**");

        InterceptorRegistration addRedPacketInterceptor = registry.addInterceptor(redPacketIntercepter());
        addRedPacketInterceptor.addPathPatterns("/base/customerGetRedPacket/**");

    }
}
